class Solution {
public:
    /*
    vector<int> multiply(const vector<int>& A) {
        vector<int> B;
        if(A.size() == 1) return B;
        for(size_t i = 0; i < A.size(); ++i){
            int temp = 1;
            for(size_t j = 0; j < A.size(); ++j){
                if(i == j) continue;
                temp *= A[j];
            }
            B.push_back(temp);
        }
        return B;
    }
    */
    
    // 双向遍历
    vector<int> multiply(const vector<int>& A) {
        vector<int> B(A.size(), 1);
        for(int i = 1; i < A.size(); ++i)
            B[i] = B[i-1] * A[i-1];
        int temp = 1;
        for(int i = A.size()-1; i >= 0; --i){
            B[i] *= temp;
            temp *= A[i];
        }
        return B;
    }
};